<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="电网排放系数" prop="sb1">
        <el-input
          v-model="queryParams.sb1"
          placeholder="请输入电网排放系数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年份" prop="sb2">
        <el-input
          v-model="queryParams.sb2"
          placeholder="请输入年份"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="t CO2e/10MWh" prop="sb3">
        <el-input
          v-model="queryParams.sb3"
          placeholder="请输入t CO2e/10MWh"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="t CO2/10MWh" prop="sb4">
        <el-input
          v-model="queryParams.sb4"
          placeholder="请输入t CO2/10MWh"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="g CH4/10MWh" prop="sb5">
        <el-input
          v-model="queryParams.sb5"
          placeholder="请输入g CH4/10MWh"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="g N2O/10MWh" prop="sb6">
        <el-input
          v-model="queryParams.sb6"
          placeholder="请输入g N2O/10MWh"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Heat CO2e EF" prop="sb7">
        <el-input
          v-model="queryParams.sb7"
          placeholder="请输入Heat CO2e EF"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="EF(ton CO2/(10^6)KJ)" prop="sb8">
        <el-input
          v-model="queryParams.sb8"
          placeholder="请输入EF(ton CO2/(10^6)KJ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="EF (g CH4/ (10^6)KJ)" prop="sb9">
        <el-input
          v-model="queryParams.sb9"
          placeholder="请输入EF (g CH4/ (10^6)KJ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="EF(gN2O/(10^6)KJ)" prop="sb10">
        <el-input
          v-model="queryParams.sb10"
          placeholder="请输入EF(gN2O/(10^6)KJ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['busi:companyEletricity:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['busi:companyEletricity:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['busi:companyEletricity:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['busi:companyEletricity:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companyEletricityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="电网排放系数" align="center" prop="sb1" />
      <el-table-column label="年份" align="center" prop="sb2" />
      <el-table-column label="t CO2e/10MWh" align="center" prop="sb3" />
      <el-table-column label="t CO2/10MWh" align="center" prop="sb4" />
      <el-table-column label="g CH4/10MWh" align="center" prop="sb5" />
      <el-table-column label="g N2O/10MWh" align="center" prop="sb6" />
      <el-table-column label="Heat CO2e EF" align="center" prop="sb7" />
      <el-table-column label="EF(ton CO2/(10^6)KJ)" align="center" prop="sb8" />
      <el-table-column label="EF (g CH4/ (10^6)KJ)" align="center" prop="sb9" />
      <el-table-column label="EF(gN2O/(10^6)KJ)" align="center" prop="sb10" />
      <el-table-column label="操作" align="center" width="155" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['busi:companyEletricity:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['busi:companyEletricity:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改电网排放系数对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" height="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="280px">
        <el-form-item label="" prop="id">
          <el-input v-model="form.id" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="电网排放系数" prop="sb1">
          <el-input v-model="form.sb1" placeholder="请输入电网排放系数" />
        </el-form-item>
        <el-form-item label="年份" prop="sb2">
          <el-input v-model="form.sb2" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="t CO2e/10MWh" prop="sb3">
          <el-input v-model="form.sb3" placeholder="请输入t CO2e/10MWh" />
        </el-form-item>
        <el-form-item label="t CO2/10MWh" prop="sb4">
          <el-input v-model="form.sb4" placeholder="请输入t CO2/10MWh" />
        </el-form-item>
        <el-form-item label="g CH4/10MWh" prop="sb5">
          <el-input v-model="form.sb5" placeholder="请输入g CH4/10MWh" />
        </el-form-item>
        <el-form-item label="g N2O/10MWh" prop="sb6">
          <el-input v-model="form.sb6" placeholder="请输入g N2O/10MWh" />
        </el-form-item>
        <el-form-item label="Heat CO2e EF" prop="sb7">
          <el-input v-model="form.sb7" placeholder="请输入Heat CO2e EF" />
        </el-form-item>
        <el-form-item label="EF(ton CO2/(10^6)KJ)" prop="sb8">
          <el-input v-model="form.sb8" placeholder="请输入EF(ton CO2/(10^6)KJ)" />
        </el-form-item>
        <el-form-item label="EF (g CH4/ (10^6)KJ)" prop="sb9">
          <el-input v-model="form.sb9" placeholder="请输入EF (g CH4/ (10^6)KJ)" />
        </el-form-item>
        <el-form-item label="EF(gN2O/(10^6)KJ)" prop="sb10">
          <el-input v-model="form.sb10" placeholder="请输入EF(gN2O/(10^6)KJ)" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCompanyEletricity, getCompanyEletricity, delCompanyEletricity, addCompanyEletricity, updateCompanyEletricity } from "@/api/busi/companyEletricity";
import fa from 'element-ui/src/locale/lang/fa'

export default {
  name: "CompanyEletricity",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 电网排放系数表格数据
      companyEletricityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sb1: undefined,
        sb2: undefined,
        sb3: undefined,
        sb4: undefined,
        sb5: undefined,
        sb6: undefined,
        sb7: undefined,
        sb8: undefined,
        sb9: undefined,
        sb10: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: false, message: "不能为空", trigger: "blur" }
        ],
        sb1: [
          { required: false, message: "电网排放系数不能为空", trigger: "blur" }
        ],
        sb2: [
          { required: false, message: "年份不能为空", trigger: "blur" }
        ],
        sb3: [
          { required: false, message: "t CO2e/10MWh不能为空", trigger: "blur" }
        ],
        sb4: [
          { required: false, message: "t CO2/10MWh不能为空", trigger: "blur" }
        ],
        sb5: [
          { required: false, message: "g CH4/10MWh不能为空", trigger: "blur" }
        ],
        sb6: [
          { required: false, message: "g N2O/10MWh不能为空", trigger: "blur" }
        ],
        sb7: [
          { required: false, message: "Heat CO2e EF不能为空", trigger: "blur" }
        ],
        sb8: [
          { required: false, message: "EF(ton CO2/(10^6)KJ)不能为空", trigger: "blur" }
        ],
        sb9: [
          { required: false, message: "EF (g CH4/ (10^6)KJ)不能为空", trigger: "blur" }
        ],
        sb10: [
          { required: false, message: "EF(gN2O/(10^6)KJ)不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询电网排放系数列表 */
    getList() {
      this.loading = true;
      listCompanyEletricity(this.queryParams).then(response => {
        this.companyEletricityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        sb1: undefined,
        sb2: undefined,
        sb3: undefined,
        sb4: undefined,
        sb5: undefined,
        sb6: undefined,
        sb7: undefined,
        sb8: undefined,
        sb9: undefined,
        sb10: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加电网排放系数";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCompanyEletricity(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改电网排放系数";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCompanyEletricity(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCompanyEletricity(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除电网排放系数编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCompanyEletricity(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
        this.$download.excel('/busi/companyEletricity/export', this.queryParams);
    }
  }
};
</script>
